import React, { Component } from "react";
import { Redirect, Switch, Route } from "react-router-dom";
import memoryUtil from "../../utils/memoryUtil";
import { Layout } from "antd";
import "./index.less";
import Header from "../../components/header";
import LeftNav from "../../components/leftNav";
import Home from "./home";
import Category from "./category";
import Product from "./product";
import Role from "./role";
import User from "./user";
import Bar from "./charts/bar";
import Line from "./charts/line";
import Pie from "./charts/pie";

const { Footer, Sider, Content } = Layout;

export default class Admin extends Component {
  render() {
    let user = memoryUtil.user;
    if (!user || !user._id) {
      return <Redirect to="/login" />;
    }
    return (
      <Layout className="admin-layout">
        <Sider>
          <LeftNav />
        </Sider>
        <Layout>
          <Header />
          <Content className="admin-content">
            <Switch>
							<Route path="/home" component={Home} />
							<Route path="/category" component={Category} />
							<Route path="/product" component={Product} />
							<Route path="/role" component={Role} />
							<Route path="/user" component={User} />
							<Route path="/charts/bar" component={Bar} />
							<Route path="/charts/line" component={Line} />
							<Route path="/charts/pie" component={Pie} />
							<Redirect to="/home" />
						</Switch>
          </Content>
          <Footer className="admin-footer">
            推荐使用谷歌浏览器，可以获得更佳页面操作体验
          </Footer>
        </Layout>
      </Layout>
    );
  }
}
